package vfs.common.command.remote;

import vfs.common.Locale;
import vfs.common.command.AbstractCommand;
import vfs.common.file.VirtualFile;
import vfs.common.file.VirtualFileNotFoundException;

/**
 * User: serge
 * Date: 22.11.13
 * Time: 5:43
 */
public class UnlockCommand extends AbstractCommand implements RemoteCommand
{
    private String path;

    @Override
    public void execute()
    {
        checkTty();
        checkUser();
        checkFilesystem();

        if (params.length != 2)
        {
            tty.broadcast(Locale.CMD_EXC_WRONG_PARAMS, user);
        }

        path = params[1];

        try
        {
            VirtualFile file = filesystem.locateFile(path, false, user);

            if (file.removeLu(user))
            {
                file.setL(false);
                tty.broadcast("Unlocked OK", user);
            }
        }
        catch (VirtualFileNotFoundException e)
        {
            e.printStackTrace();

            tty.broadcast(Locale.CMD_EXC_PATH_NOT_FOUND, user);
        }
    }
}
